home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / hack / 3_1_3 / sys / msdos / video.c < prev   
Encoding:
C/C++ Source or Header  |  1993-07-01  |  15.9 KB  |  765 lines

  1. /*   SCCS Id: @(#)video.c   3.1     93/06/28                        */
  2. /*   Copyright (c) NetHack PC Development Team 1993                 */
  3. /*   NetHack may be freely redistributed.  See license for details. */
  4. /*                                                                  */
  5. /*
  6.  * video.c - Hardware video support
  7.  *                                                  
  8.  *Edit History:
  9.  *     Initial Creation              M. Allison      93/04/04
  10.  *     Add colour support            M. Allison      93/04/06
  11.  *     Fix cl_end()                  M. Allison      93/04/11
  12.  *     Use CO,LI in decl.c           M. Allison      93/04/24
  13.  *     Add djgpp support             K. Smolkowski   93/04/26
  14.  *     Add runtime monoadapter check M. Allison      93/05/09
  15.  *     Fix grays                     M. Allison      93/06/15
  16.  *     MONO_CHECK not BIOS specific  M. Allison      93/06/19
  17.  *     Add .cnf videoshades support  M. Allison      93/06/25
  18.  *     Add .cnf videocolors support  M. Allison      93/06/27
  19.  *     Make tty_delay_output() work  M. Allison      93/06/28
  20.  */
  21.  
  22. #include "hack.h"
  23.  
  24. #include <dos.h>
  25.  
  26. /*
  27.  * Choose compile options for different compilers/environments.
  28.  * Current optional features in video.c :
  29.  *
  30.  *     MONO_CHECK     Enables runtime checking for monochrome
  31.  *                    adapter. 93/06/19
  32.  *     ENABLE_SLEEP   Enables the tty_delay_output() function. 93/06/28
  33.  *
  34.  */
  35.  
  36. # ifdef SCREEN_BIOS
  37. # define MONO_CHECK        /* Video BIOS can do the check       */ 
  38. #  if defined(_MSC_VER) && _MSC_VER >= 700
  39. # define ENABLE_SLEEP        /* enable napping for visual effects */
  40. #  endif
  41. # endif
  42.  
  43. # ifdef SCREEN_DJGPPFAST
  44. /*# define MONO_CHECK         /* djgpp should be able to do check  */ 
  45. # define ENABLE_SLEEP        /* enable napping for visual effects */
  46. # endif
  47.  
  48. # ifdef PC9801
  49. #  ifdef MONO_CHECK
  50. #undef MONO_CHECK        /* Don't suppose it can do the check */
  51. #  endif                        /* Can it?                           */
  52. # endif
  53.  
  54. /*
  55.  * PC interrupts
  56.  */
  57. #ifdef PC9801
  58. #define CRT_BIOS    0x18
  59. #else
  60. #define VIDEO_BIOS  0x10
  61. #endif
  62. #define DOSCALL        0x21
  63.  
  64. /*
  65.  * Character Attributes
  66.  */
  67. #define ATTRIB_NORMAL         0x07    /* Normal attribute */
  68. #define ATTRIB_INTENSE           0x0f    /* Intense White */
  69.  
  70. #ifdef MONO_CHECK
  71. #define ATTRIB_MONO_UNDERLINE 0x01    /* Underlined,white */
  72. #define ATTRIB_MONO_BLINK     0x87    /* Flash bit, white */
  73. #define ATTRIB_MONO_REVERSE   0x70    /* Black on white */
  74. #endif
  75.  
  76. /*
  77.  * Video BIOS functions
  78.  */
  79. #if defined(PC9801)
  80. #define SETCURPOS   0x13    /* Set Cursor Position */
  81. #define SENSEMODE   0x0b    /* Sense CRT Mode */
  82. #else
  83. #define SETCURPOS   0x02    /* Set Cursor Position */
  84. #endif
  85.  
  86. #define GETCURPOS   0x03    /* Get Cursor Position */
  87. #define GETMODE     0x0f    /* Get Video Mode */
  88. #define SETMODE     0x00    /* Set Video Mode */
  89. #define SETPAGE     0x05    /* Set Video Page */
  90. #define FONTINFO    0x1130  /* Get Font Info */
  91. #define SCROLL      0x06    /* Scroll or initialize window */
  92. #define PUTCHARATT  0x09    /* Write attribute & char at cursor */
  93.  
  94.  
  95. #ifdef OVLB
  96.  
  97. void
  98. get_scr_size()
  99. {
  100.     union REGS regs;
  101.  
  102.     if (!flags.BIOS) {        /* assume standard screen size */
  103.         CO = 80;
  104.         LI = 24;
  105.         return;
  106.     }
  107.  
  108. # ifdef PC9801
  109.     regs.h.ah = SENSEMODE;
  110.     int86(CRT_BIOS, ®s, ®s);
  111.  
  112.     LI = (regs.h.al & 0x01) ? 20 : 25;
  113.     CO = (regs.h.al & 0x02) ? 40 : 80;
  114. # else 
  115.     regs.x.ax = FONTINFO;
  116.     regs.x.bx = 0;            /* current ROM BIOS font */
  117.     regs.h.dl = 24;            /* default row count */
  118.                     /* in case no EGA/MCGA/VGA */
  119.     int86(VIDEO_BIOS, ®s, ®s); /* Get Font Information */
  120.  
  121.     /* MDA/CGA/PCjr ignore INT 10h, Function 11h, but since we
  122.      * cleverly loaded up DL with the default, everything's fine.
  123.      *
  124.      * Otherwise, DL now contains rows - 1.  Also, CX contains the
  125.      * points (bytes per character) and ES:BP points to the font
  126.      * table.  -3.
  127.      */
  128.  
  129.     regs.h.ah = GETMODE;
  130.     int86(VIDEO_BIOS, ®s, ®s); /* Get Video Mode */
  131.  
  132.     /* This goes back all the way to the original PC.  Completely
  133.      * safe.  AH contains # of columns, AL contains display mode,
  134.      * and BH contains the active display page.
  135.      */
  136.  
  137.     LI = regs.h.dl + 1;
  138.     CO = regs.h.ah;
  139. # endif /* PC9801 */
  140. }
  141. #endif /*OVLB*/
  142.  
  143. #ifdef NO_TERMS
  144.  
  145. #include "wintty.h"
  146.  
  147. # ifdef SCREEN_DJGPPFAST
  148. #include <pc.h>
  149. # endif
  150.  
  151. void FDECL(cmov, (int, int));
  152. void FDECL(nocmov, (int, int));
  153.  
  154. # ifdef TEXTCOLOR
  155. char ttycolors[MAXCOLORS];
  156. static void NDECL(init_ttycolor);
  157. # endif /* TEXTCOLOR */
  158.  
  159. # ifdef SCREEN_BIOS
  160. void FDECL(gotoxy, (int,int));
  161. void FDECL(get_cursor, (int *, int *));
  162. # endif
  163.  
  164. # ifdef SCREEN_DJGPPFAST
  165. #define gotoxy(x,y) ScreenSetCursor(y,x)
  166. #define get_cursor(x,y) ScreenGetCursor(y,x)
  167. # endif
  168.  
  169. # ifdef MONO_CHECK
  170. int  NDECL(monoadapt_check);
  171. # endif
  172.  
  173. /* 
  174.  *  LI, CO are ifdefs of a data structure in decl.c, and are initialized
  175.  *  by get_scr_size()
  176.  */
  177. char g_attribute;        /* Current attribute to use */
  178.  
  179. # ifdef MONO_CHECK
  180. int monoflag;            /* 0 = not monochrome, else monochrome */
  181. # endif
  182.  
  183. #ifdef OVLB
  184.  
  185. void
  186. backsp()
  187. {
  188.     int x,y;
  189.  
  190.     get_cursor(&x, &y);
  191.     if (x > 0) x = x-1;
  192.     gotoxy(x,y);
  193.     xputc(' ');
  194.     gotoxy(x,y);
  195. }
  196.  
  197. #endif /* OVLB */
  198. #ifdef OVL0
  199.  
  200. void
  201. clear_screen()
  202. /* djgpp provides ScreenClear(), but in version 1.09 it is broken
  203.  * so for now we just use the BIOS Routines
  204.  */
  205. {
  206.  
  207.     union REGS regs;
  208.  
  209.     regs.h.dl = CO - 1;      /* columns */
  210.     regs.h.dh = LI - 1;          /* rows */
  211.     regs.x.cx = 0;              /* CL,CH = x,y of upper left */
  212.     regs.x.ax = 0;
  213.     regs.x.bx = 0;
  214.     regs.h.bh = ATTRIB_NORMAL;
  215.     regs.h.ah = SCROLL;
  216.                       /* DL,DH = x,y of lower right */
  217.     int86(VIDEO_BIOS, ®s, ®s);  /* Scroll or init window */
  218.     gotoxy(0,0);
  219. }
  220.  
  221. void
  222. cl_end()    /* clear to end of line */
  223. {
  224.     union REGS regs;
  225.     int x,y,count;
  226.  
  227.     x = ttyDisplay->curx;
  228.     y = ttyDisplay->cury;
  229.     gotoxy(x,y);
  230.     count = CO - x;
  231.     regs.h.ah = PUTCHARATT;    /* write attribute & character */    
  232.     regs.h.al = ' ';        /* character */
  233.     regs.h.bh = 0;            /* display page */
  234.                     /* BL = attribute */
  235.     regs.h.bl = ATTRIB_NORMAL;
  236.     regs.x.cx = count;
  237.     if (count != 0)
  238.         int86(VIDEO_BIOS, ®s, ®s); /* write attribute 
  239.                             & character */
  240.     tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1,
  241.                         (int)ttyDisplay->cury);
  242. }
  243.  
  244. void
  245. cl_eos()    /* clear to end of screen */
  246. {
  247.     union REGS regs;
  248.     int x,y;
  249.  
  250.     get_cursor(&x, &y);
  251.     cl_end();            /* clear to end of line */
  252.     gotoxy(0,(y < (LI-1) ? y+1 : (LI-1)));        
  253.     regs.h.dl = CO-1;      /* X  of lower right */
  254.     regs.h.dh = LI-1;          /* Y  of lower right */
  255.     regs.h.cl = 0;              /* X  of upper left */
  256.                         /* Y (row)  of upper left */
  257.     regs.h.ch = (y < (LI-1) ? y+1 :(LI-1));
  258.     regs.x.cx = 0; 
  259.     regs.x.ax = 0;
  260.     regs.x.bx = 0;
  261.     regs.h.bh = ATTRIB_NORMAL;
  262.     regs.h.ah = SCROLL;
  263.     int86(VIDEO_BIOS, ®s, ®s); /* Scroll or initialize window */
  264.     tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1,
  265.                         (int)ttyDisplay->cury);
  266. }
  267.  
  268. void
  269. cmov(x, y)
  270. register int x, y;
  271. {
  272.     ttyDisplay->cury = y;
  273.     ttyDisplay->curx = x;
  274.     gotoxy(x,y);
  275. }
  276.  
  277. # endif /* OVL0 */
  278. # ifdef OVLB
  279.  
  280. int
  281. has_color(int color)
  282. {
  283. #  ifdef TEXTCOLOR
  284.     return
  285. #   ifdef MONO_CHECK
  286.     (monoflag) ? 0 :
  287. #   endif
  288.     1;
  289. #  else
  290.     return 0;
  291. #  endif
  292. }
  293.  
  294. # endif /* OVLB */
  295. # ifdef OVL0
  296.  
  297. void
  298. home()
  299. {
  300.     tty_curs(BASE_WINDOW, 1, 0);
  301.     ttyDisplay->curx = ttyDisplay->cury = 0;
  302.     gotoxy(0,0);
  303. }
  304.  
  305. void
  306. nocmov(x, y)
  307. int x,y;
  308. {
  309.     gotoxy(x,y);
  310. }
  311.  
  312. void
  313. standoutbeg()
  314. {
  315.     g_attribute = ATTRIB_INTENSE;    /* intense white */
  316. }
  317.  
  318. void
  319. standoutend()
  320. {
  321.     g_attribute = ATTRIB_NORMAL;    /* normal white */
  322. }
  323.  
  324. # endif /* OVL0 */
  325. # ifdef OVLB
  326.  
  327. void
  328. term_end_attr(int attr)
  329. {
  330.         g_attribute = ATTRIB_NORMAL;    /* normal white */
  331. }
  332.  
  333. void
  334. term_end_color(void)
  335. {
  336.     g_attribute = ATTRIB_NORMAL;    /* normal white  (harmless) */
  337. }
  338.  
  339. void
  340. term_end_raw_bold(void)
  341. {
  342.     standoutend(); 
  343. }
  344.  
  345. void
  346. term_start_attr(int attr)
  347. {
  348.     switch(attr){
  349.  
  350.     case ATR_ULINE:
  351. #  ifdef MONO_CHECK
  352.         if (monoflag) {
  353.             g_attribute = ATTRIB_MONO_UNDERLINE;
  354.         } else {
  355.             g_attribute = ATTRIB_INTENSE;
  356.         }
  357.         break;
  358. #  endif
  359.     case ATR_BOLD:
  360.         g_attribute = ATTRIB_INTENSE;
  361.         break;
  362.     case ATR_BLINK:
  363. #  ifdef MONO_CHECK
  364.         if (monoflag) {
  365.             g_attribute = ATTRIB_MONO_BLINK;
  366.         } else {
  367.             g_attribute = ATTRIB_INTENSE;
  368.         }
  369.         break;
  370. #  endif
  371.     case ATR_INVERSE:
  372. #  ifdef MONO_CHECK
  373.         if (monoflag) {
  374.             g_attribute = ATTRIB_MONO_REVERSE;
  375.         } else {
  376.             g_attribute = ATTRIB_INTENSE;
  377.         }
  378.         break;
  379. #  endif
  380.     default:
  381.         g_attribute = ATTRIB_NORMAL;
  382.         break;
  383.     }                
  384. }
  385.  
  386.  
  387. void
  388. term_start_color(int color)
  389. {
  390. #  ifdef TEXTCOLOR
  391.     short attr;
  392.  
  393. #   ifdef MONO_CHECK
  394.     if (monoflag) {
  395.         g_attribute = ATTRIB_NORMAL;
  396.     } else {
  397. #   endif
  398.         if (color >= 0 && color < MAXCOLORS) {
  399.             g_attribute = ttycolors[color];
  400.           }
  401. #   ifdef MONO_CHECK
  402.     }
  403. #   endif
  404. #  endif
  405. }
  406.  
  407. void
  408. term_start_raw_bold(void)
  409. {
  410.     standoutbeg();
  411. }
  412.  
  413. # endif /* OVLB */
  414. # ifdef OVL0
  415.  
  416. void
  417. tty_delay_output()
  418. {
  419.     /* delay 50 ms - now uses clock() which is ANSI C */
  420. #  if defined(ENABLE_SLEEP) || defined(__STDC__)
  421.     clock_t goal;
  422.  
  423.     goal = 50 + clock();
  424.     while ( goal > clock()) {
  425.         /* do nothing */
  426.     }
  427. #  endif /* ENABLE_SLEEP || __STDC__*/
  428. }
  429. # endif /* OVL0 */
  430.  
  431. # ifdef OVLB
  432. void
  433. tty_end_screen()
  434. {
  435.     clear_screen();
  436. }
  437.  
  438. void
  439. tty_nhbell()
  440. {
  441.         union REGS regs;
  442.  
  443.         if (flags.silent) return;
  444.         regs.h.dl = 0x07;        /* bell */
  445.         regs.h.ah = 0x02;         /* Character Output */
  446.         int86(DOSCALL, ®s, ®s);
  447. }
  448.  
  449. void
  450. tty_number_pad(state)
  451. int state;
  452. {
  453. }
  454.  
  455. void
  456. tty_startup(wid, hgt)
  457.     int *wid, *hgt;
  458. {
  459.     if (CO && LI) {
  460.         *wid = CO;
  461.         *hgt = LI;
  462.     } else {
  463.         *wid = CO = 80;
  464.         *hgt = LI = 25;
  465.     }
  466. #  ifdef MONO_CHECK
  467.     monoflag = monoadapt_check();
  468.     if (!monoflag) {
  469. #  endif
  470. #  ifdef TEXTCOLOR
  471.        init_ttycolor();
  472. #  endif
  473. #  ifdef MONO_CHECK
  474.     }
  475. #  endif
  476.     g_attribute = ATTRIB_NORMAL;
  477. }
  478.  
  479. void
  480. tty_start_screen()
  481. {
  482.     if (flags.num_pad) tty_number_pad(1);   /* make keypad send digits */
  483. }
  484.  
  485. # endif /* OVLB */
  486. # ifdef OVL0
  487.  
  488. void
  489. xputs(s)
  490. const char *s;
  491. {
  492.     char c;
  493.     int x,y;
  494.  
  495.     x = ttyDisplay->curx;
  496.     y = ttyDisplay->cury;
  497.     if (s != NULL) {
  498.         while (*s != '\0') {
  499.             gotoxy(x,y);
  500.             c = *s++;
  501.             xputc(c);
  502.             if (x < (CO-1)) x++;
  503.             gotoxy(x,y);
  504.         }
  505.     }
  506. }
  507.  
  508. void
  509. xputc(ch)    /* write out character (and attribute) */
  510. char ch;
  511. {
  512. #  ifdef SCREEN_BIOS
  513.     union REGS regs;
  514. #  endif
  515.     int x,y;
  516.     char attribute;
  517.  
  518. #  ifdef MONO_CHECK
  519.     attribute = ((g_attribute == 0) ? ATTRIB_NORMAL : g_attribute);
  520. #  else
  521.     attribute = (((g_attribute > 0) && (g_attribute < MAXCOLORS)) ?
  522.             g_attribute : ATTRIB_NORMAL);
  523. #  endif
  524.  
  525. #  ifdef SCREEN_DJGPPFAST
  526.     get_cursor(&x,&y);
  527.     ScreenPutChar((int)ch,(int)attribute,x,y);
  528. #  endif
  529.  
  530. #  ifdef SCREEN_BIOS
  531.     regs.h.ah = PUTCHARATT;    /* write attribute & character */
  532.     regs.h.al = ch;            /* character */
  533.     regs.h.bh = 0;            /* display page */
  534.     regs.h.bl = attribute;        /* BL = attribute */
  535.     regs.x.cx = 1;            /* one character */
  536.     int86(VIDEO_BIOS, ®s, ®s); /* write attribute & character */
  537.     get_cursor(&x,&y);
  538. #  endif /* SCREEN_BIOS */
  539.     if (x < (CO -1 )) ++x;
  540.     gotoxy(x,y);
  541. }
  542.  
  543. /*
  544.  *  Supporting routines.
  545.  */
  546. #  ifdef SCREEN_BIOS
  547. void
  548. get_cursor(x,y)    /* get cursor position */
  549. int *x, *y;
  550. {
  551.     union REGS regs;
  552.  
  553.     regs.x.dx = 0;
  554.     regs.h.ah = GETCURPOS;        /* get cursor position */
  555.     regs.x.cx = 0;
  556.     regs.x.bx = 0;    
  557.     int86(VIDEO_BIOS, ®s, ®s); /* Get Cursor Position */
  558.     *x = regs.h.dl;
  559.     *y = regs.h.dh;
  560. }
  561.  
  562. void
  563. gotoxy(x,y)
  564. int x,y;
  565. {
  566.     union REGS regs;
  567.  
  568.     regs.h.ah = SETCURPOS;
  569. # ifdef PC9801
  570.     regs.x.dx = 2 * (80 * y + x);
  571.     int86(CRT_BIOS, ®s, ®s);    /* Set Cursor Position */
  572. # else
  573.     regs.h.bh = 0;            /* display page */
  574.     regs.h.dh = y;            /* row */
  575.     regs.h.dl = x;            /* column */
  576.     int86(VIDEO_BIOS, ®s, ®s); /* Set Cursor Position */
  577. # endif
  578.  
  579.     /* This, too, goes back all the way to the original PC.  If
  580.      * we ever get so fancy as to swap display pages (i doubt it),
  581.      * then we'll need to set BH appropriately.  This function
  582.      * returns nothing.  -3.
  583.      */
  584. }
  585. #  endif /* SCREEN_BIOS */ 
  586.  
  587. #  ifdef MONO_CHECK
  588. int monoadapt_check()
  589. {
  590.     union REGS regs;
  591.  
  592.     regs.h.al = 0;
  593.     regs.h.ah = GETMODE;            /* get video mode */
  594.     int86(VIDEO_BIOS, ®s, ®s);
  595.     return (regs.h.al == 7) ? 1 : 0;    /* 7 means monochrome mode */
  596. }
  597. #  endif /* MONO_CHECK */
  598.  
  599. # endif /* OVL0 */
  600.  
  601. # ifdef TEXTCOLOR
  602. #  ifdef OVLB
  603.  
  604. /*
  605.  * BLACK                0
  606.  * RED                  1
  607.  * GREEN                2
  608.  * BROWN                3       low-intensity yellow
  609.  * BLUE                 4
  610.  * MAGENTA              5
  611.  * CYAN                 6
  612.  * GRAY                 7       low-intensity white
  613.  * NO_COLOR             8
  614.  * ORANGE_COLORED       9
  615.  * BRIGHT_GREEN         10
  616.  * YELLOW               11
  617.  * BRIGHT_BLUE          12
  618.  * BRIGHT_MAGENTA       13
  619.  * BRIGHT_CYAN          14
  620.  * WHITE                15
  621.  * MAXCOLORS            16
  622.  * BRIGHT               8
  623.  */
  624.  
  625. #  ifdef VIDEOSHADES
  626. /* assign_videoshades() is prototyped in extern.h */
  627. int shadeflag;                    /* shades are initialized */
  628. int colorflag;                    /* colors are initialized */
  629. char *schoice[3] = {"dark","normal","light"};
  630. char *shade[3];
  631. #  endif /* VIDEOSHADES */
  632.  
  633. static void
  634. init_ttycolor()
  635. {
  636. #   ifdef VIDEOSHADES
  637.     if (!shadeflag) {
  638.         ttycolors[BLACK] = 8;           /*  8 = dark gray */
  639.         ttycolors[WHITE] = 15;          /* 15 = bright white */
  640.         ttycolors[GRAY]  = 7;        /*  7 = normal white */
  641.         shade[0] = schoice[0];
  642.         shade[1] = schoice[1];
  643.         shade[2] = schoice[2];
  644.     }
  645. #   else
  646.     ttycolors[BLACK] = 7;            /*  mapped to white */
  647.     ttycolors[WHITE] = 7;            /*  mapped to white */
  648.     ttycolors[GRAY]  = 7;            /*  mapped to white */
  649. #   endif
  650.  
  651. #   ifdef VIDEOSHADES
  652.         if (!colorflag) {
  653. #   endif
  654.         ttycolors[RED] = 4;            /*  4 = red */
  655.         ttycolors[GREEN] = 2;            /*  2 = green */
  656.         ttycolors[BROWN] = 6;            /*  6 = brown */
  657.         ttycolors[BLUE] = 1;            /*  1 = blue */
  658.         ttycolors[MAGENTA] = 5;            /*  5 = magenta */
  659.         ttycolors[CYAN] = 3;            /*  3 = cyan */
  660.         ttycolors[BRIGHT] = 15;            /* 15 = bright white */
  661.         ttycolors[ORANGE_COLORED] = 12;        /* 12 = light red */
  662.         ttycolors[BRIGHT_GREEN] = 10;        /* 10 = light green */
  663.         ttycolors[YELLOW] = 14;            /* 14 = yellow */
  664.         ttycolors[BRIGHT_BLUE] = 9;        /*  9 = light blue */
  665.         ttycolors[BRIGHT_MAGENTA] = 13;        /* 13 = light magenta */
  666.         ttycolors[BRIGHT_CYAN] = 11;        /* 11 = light cyan */
  667. #   ifdef VIDEOSHADES
  668.     }
  669. #   endif
  670. }
  671.  
  672. #   ifdef VIDEOSHADES
  673. int assign_videoshades(uchar *choiceptr,int linelen)
  674. {
  675.     char choices[120];
  676.     char *cptr, *cvalue[3];
  677.     int i,icolor;
  678.  
  679.     strncpy(choices,choiceptr,linelen);
  680.     choices[linelen] = '\0';
  681.     cvalue[0] = choices;
  682.  
  683.         /* find the next ' ' or tab */
  684.         cptr = index(cvalue[0], ' ');
  685.         if (!cptr) cptr = index(cvalue[0], '\t');
  686.         if (!cptr) return 0;
  687.     *cptr = '\0';
  688.         /* skip  whitespace between '=' and value */
  689.         do { ++cptr; } while (isspace(*cptr));
  690.     cvalue[1] = cptr;
  691.  
  692.         cptr = index(cvalue[1], ' ');
  693.         if (!cptr) cptr = index(cvalue[1], '\t');
  694.         if (!cptr) return 0;
  695.     *cptr = '\0';
  696.         do { ++cptr; } while (isspace(*cptr));
  697.     cvalue[2] = cptr;
  698.  
  699.     for (i=0; i < 3; ++i) {
  700.         switch(i) {
  701.             case 0: icolor = BLACK;
  702.                 break;
  703.             case 1: icolor = GRAY;
  704.                 break;
  705.             case 2: icolor = WHITE;
  706.                 break;
  707.         }
  708.  
  709.         shadeflag = 1;            
  710.         if ((strncmpi(cvalue[i],"black",5) == 0) ||
  711.             (strncmpi(cvalue[i],"dark",4) == 0)) {
  712.             shade[i] = schoice[0];
  713.             ttycolors[icolor] = 8;  /* dark gray */
  714.         } else if ((strncmpi(cvalue[i],"gray",4) == 0) ||
  715.                    (strncmpi(cvalue[i],"grey",4) == 0) ||
  716.                (strncmpi(cvalue[i],"medium",6) == 0) ||
  717.                (strncmpi(cvalue[i],"normal",6) == 0)) {
  718.             shade[i] = schoice[1];
  719.             ttycolors[icolor] = 7;  /* regular gray */
  720.         } else if ((strncmpi(cvalue[i],"white",5) == 0) ||
  721.                (strncmpi(cvalue[i],"light",5) == 0)) {
  722.             shade[i] = schoice[2];
  723.             ttycolors[icolor] = 15;  /* bright white */
  724.         } else {
  725.             shadeflag = 0;
  726.             return 0;
  727.         }
  728.     }
  729.     return 1;
  730. }
  731.  
  732. /*
  733.  * Process NetHack.cnf option VIDEOCOLORS=
  734.  * Left to right assignments for: 
  735.  *     red green brown blue magenta cyan orange br.green yellow 
  736.  *     br.blue br.mag br.cyan
  737.  *
  738.  * Default Mapping: 4 2 6 1 5 3 12 10 14 9 13 11
  739.  */
  740. int assign_videocolors(uchar *tmpcolor,int len)
  741. {
  742.     int i,icolor,max1,max2;
  743.  
  744.     init_ttycolor();    /* in case nethack.cnf entry wasn't complete */
  745.     icolor = RED;
  746.     for( i = 0; i < len; ++i) {
  747.         if (icolor < (WHITE)) {
  748.             ttycolors[icolor++] = tmpcolor[i];
  749.             if ((icolor > CYAN) && (icolor < ORANGE_COLORED)) {
  750.                  icolor = ORANGE_COLORED;
  751.             }
  752.         }
  753.     }
  754.     colorflag = 1;
  755.     return 1;
  756. }
  757. #   endif /* VIDEOSHADES */
  758.  
  759. #  endif /* OVLB */
  760. # endif /* TEXTCOLOR */
  761.  
  762. #endif /* NO_TERMS */
  763.  
  764. /* video.c */
  765.